package Midium;
//11.盛最多水的容器
public class Solution11 {
    public int maxArea(int[] height) {
        int max = 0;
        for(int i = 0 ; i < height.length;i++){
            for(int j = i+1;j<height.length;j++){
                int sqrt = (j-i)*min(height[i],height[j]);
                max = max > sqrt?max:sqrt;
            }
        }
        return max;
    }
    public int min(int a, int b){
        return a<b?a:b;
    }
    //解法2 时间复杂度为O(N)
    public int maxArea2(int[] height) {
        int i = 0 , j = height.length-1;
        int max = Math.min(height[i],height[j])*(j-i);
        while (i<j){
            if(height[i]<height[j]){
                int sqrt = Math.min(height[++i],height[j])*(j-i);
                max = Math.max(max,sqrt);
            }else {
                int sqrt = Math.min(height[i],height[--j])*(j-i);
                max = Math.max(max,sqrt);
            }
        }
        return max;
    }

}
